import pymysql

# 打开数据库连接
db = pymysql.connect("rdsu70z23ct48w8t9584o.mysql.rds.aliyuncs.com", "jusrs9guttii", "qushu_2018", "boxandneedle")

# 使用cursor()方法获取操作游标 
cursor = db.cursor()

# SQL 插入语句
# sql = "INSERT INTO EMPLOYEE(FIRST_NAME,LAST_NAME, AGE, SEX, INCOME) VALUES ('Mac', 'Mohan', 20, 'M', 2000)"
d = ('Pro', 'beijing', 23, 'F', 5000)
sql = "INSERT INTO test(FIRST_NAME,LAST_NAME, AGE, SEX, INCOME) VALUES " + str(d)
try:
    # 执行sql语句
    cursor.execute(sql)
    # 提交到数据库执行
    db.commit()
except:
    # 如果发生错误则回滚
    db.rollback()

    # 关闭数据库连接
    db.close()
